package math;

import java.util.ArrayList;
import java.util.List;




public class WLeastAbsMethod implements MEstimate {
	
	public Double estimate (List<Double> V, List<Double> U) {
		Double eps = 0.00001;
		LeastSquareMethod lsm = new LeastSquareMethod();
		WLeastSquareMethod wlsm = new WLeastSquareMethod();
		Double coeff0 = lsm.estimate(V, U);
		Double coeff = coeff0;
		
		do {
			coeff0 = coeff;
			ArrayList<Double> W = new ArrayList<Double>();
			for (int i=0; i<U.size(); i++) {
				W.add(Math.pow(U.get(i), 2.0)/Math.abs(V.get(i)-coeff0*U.get(i)));
//				W.add(Math.abs(U.get(i))/Math.abs(V.get(i)-coeff0*U.get(i)));
			}
			coeff = wlsm.estimate(V, U, W);
		} while (Math.abs(coeff-coeff0)>eps);
		
		return coeff;
	}

	@Override
	public Vector2D estimateFull(List<Double> V, List<Double> U) {
		// TODO Auto-generated method stub
		return null;
	}

}
